package club.emergency.wechat.feedback.operate.provider.impl;

import club.emergency.wechat.common.response.ResponseEntity;
import club.emergency.wechat.common.response.StatusCode;
import club.emergency.wechat.feedback.operate.FeedbackOperate;
import club.emergency.wechat.model.feedback.Feedback;
import club.emergency.wechat.persistence.feedback.FeedbackMapper;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Create with IntelliJ IDEA
 * Project Name: business
 * Package Name: club.emergency.wechat.feedback.operate.provider.impl
 * Date: 2018/12/9
 *
 * @author: 快乐的小菌菌
 * Description:
 */
@RestController
public class FeedbackOperateImpl implements FeedbackOperate {

    private FeedbackMapper feedbackMapper;

    public FeedbackOperateImpl(FeedbackMapper feedbackMapper) {
        this.feedbackMapper = feedbackMapper;
    }

    @Override
    public String save(@RequestBody Feedback feedback) {
        feedback.setDeal(1);
        feedbackMapper.insert(feedback);
        return ResponseEntity.ok(StatusCode.DB_SAVE_OK, "反馈记录新增成功！", feedback.getId());
    }

    @Override
    public String doDeal(@RequestParam("id") Long id) {
        Feedback feedback = new Feedback();
        feedback.setId(id);
        feedback.setDeal(0);
        int i = feedbackMapper.updateById(feedback);
        if (i == 0) {
            return ResponseEntity.error(StatusCode.DB_MODIFY_ERROR, "反馈标记处理错误！");
        }
        return ResponseEntity.ok(StatusCode.DB_MODIFY_OK, "反馈标记处理修改成功！");
    }

}
